In [1]:
from __future__ import print_function, division

In [2]:
# This changes the current directory to the base saga directory - make sure to run this first!
# This is necessary to be able to import the py files and use the right directories,
# while keeping all the notebooks in their own directory.
import os
import sys
import time
import shutil

import urllib

if 'saga_base_dir' not in locals():
    saga_base_dir = os.path.abspath('..')
if saga_base_dir not in sys.path:
    os.chdir(saga_base_dir)

In [3]:
import hosts
import decals

import numpy as np

from astropy import units as u
from astropy.coordinates import SkyCoord, Angle
from astropy import table
from astropy.table import Table
from astropy.io import fits

from astropy.utils import data

import tqdm
from IPython import display

In [4]:
%matplotlib inline
from matplotlib import style, pyplot as plt

plt.style.use('seaborn-deep')
plt.rcParams['image.cmap'] = 'viridis'
plt.rcParams['image.origin'] = 'lower'
plt.rcParams['figure.figsize'] = (14, 8)

Load the bricks and SAGA hosts


In [5]:
bricks = Table.read('decals_dr4/survey-bricks.fits.gz')
bricksdr3 = Table.read('decals_dr3/survey-bricks-dr3.fits.gz')
bricksdr4 = Table.read('decals_dr4/survey-bricks-dr4.fits.gz')

In [6]:
paper1nsas_comp = [166313,147100,165536,61945,132339,149781,33446,150887]
paper1nsas_incomp = [161174,85746,145729,140594,126115,13927,137625,129237]
paper1nsas = paper1nsas_comp + paper1nsas_incomp

In [7]:
hostobjs = hosts.get_saga_hosts_from_google()
for host in hostobjs:
    host.fnsdss = 'catalogs/base_sql_nsa{}.fits.gz'.format(host.nsaid)
    
hostsbyname = {h.name:h for h in hostobjs}

paperhosts = [h for h in hostobjs if h.nsaid in paper1nsas]
assert len(paperhosts) == len(paper1nsas)


Using cached version of google hosts list from file "hosts_dl.pkl2"

In [8]:
host_bricks_3 = decals.find_host_bricks(paperhosts, bricksdr3, bricks)
host_bricks_4 = decals.find_host_bricks(paperhosts, bricksdr4, bricks)

host_bricks_dct = {3:host_bricks_3, 4:host_bricks_4}

Build combined catalogs for every host


In [9]:
for hostobj in paperhosts:
    hbricks = host_bricks_3[host_bricks_3['closest_host_name'] == hostobj.name]
    catfn = 'decals_dr3/'

In [10]:
def load_host_catalog(hostobj, drnum):
    host_bricks = host_bricks_dct[drnum]
    tabs = []
    for brick in host_bricks[host_bricks['closest_host_name'] == hostobj.name]:
        catfn = 'decals_dr{}/catalogs/tractor-{}.fits'.format(drnum, brick['brickname'])
        cat = Table.read(catfn)
        cat['objname'] = ['{}-{}'.format(row['brickname'], row['objid']) for row in cat]
        tabs.append(cat)
    if tabs:
        return table.vstack(tabs)

In [11]:
for hostobj in tqdm.tqdm_notebook(paperhosts):
    hostobj.cats3 = load_host_catalog(hostobj, 3)
    
[(hostobj.name, len(hostobj.cats3)) for hostobj in paperhosts if hostobj.cats3 is not None]


Widget Javascript not detected.  It may not be installed or enabled properly.
WARNING: UnitsWarning: '1/deg^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING: UnitsWarning: 'nanomaggy' did not parse as fits unit: At col 0, Unit 'nanomaggy' not supported by the FITS standard.  [astropy.units.core]
WARNING: UnitsWarning: '1/nanomaggy^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING: UnitsWarning: '1/arcsec^2' did not parse as fits unit: Numeric factor not supported by FITS [astropy.units.core]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P4' types <type 'str'> and <type 'str'>, choosing TR_D_P4='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P5' types <type 'str'> and <type 'str'>, choosing TR_D_P5='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P6' types <type 'str'> and <type 'str'>, choosing TR_D_P6='shape.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P4' types <type 'str'> and <type 'str'>, choosing TR_C_P4='fracDev.FracDev' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P5' types <type 'str'> and <type 'str'>, choosing TR_C_P5='shapeExp.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P6' types <type 'str'> and <type 'str'>, choosing TR_C_P6='shapeExp.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P7' types <type 'str'> and <type 'str'>, choosing TR_C_P7='shapeExp.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P8' types <type 'str'> and <type 'str'>, choosing TR_C_P8='shapeDev.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P9' types <type 'str'> and <type 'str'>, choosing TR_C_P9='shapeDev.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P10' types <type 'str'> and <type 'str'>, choosing TR_C_P10='shapeDev.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P4' types <type 'str'> and <type 'str'>, choosing TR_E_P4='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P5' types <type 'str'> and <type 'str'>, choosing TR_E_P5='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P6' types <type 'str'> and <type 'str'>, choosing TR_E_P6='shape.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P4' types <type 'str'> and <type 'str'>, choosing TR_D_P4='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P5' types <type 'str'> and <type 'str'>, choosing TR_D_P5='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P6' types <type 'str'> and <type 'str'>, choosing TR_D_P6='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P4' types <type 'str'> and <type 'str'>, choosing TR_C_P4='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P5' types <type 'str'> and <type 'str'>, choosing TR_C_P5='fracDev.FracDev' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P6' types <type 'str'> and <type 'str'>, choosing TR_C_P6='shapeExp.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P7' types <type 'str'> and <type 'str'>, choosing TR_C_P7='shapeExp.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P8' types <type 'str'> and <type 'str'>, choosing TR_C_P8='shapeExp.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P9' types <type 'str'> and <type 'str'>, choosing TR_C_P9='shapeDev.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P10' types <type 'str'> and <type 'str'>, choosing TR_C_P10='shapeDev.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P4' types <type 'str'> and <type 'str'>, choosing TR_E_P4='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P5' types <type 'str'> and <type 'str'>, choosing TR_E_P5='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P6' types <type 'str'> and <type 'str'>, choosing TR_E_P6='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P3' types <type 'str'> and <type 'str'>, choosing TR_C_P3='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P3' types <type 'str'> and <type 'str'>, choosing TR_E_P3='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_G_P3' types <type 'str'> and <type 'str'>, choosing TR_G_P3='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_S_P3' types <type 'str'> and <type 'str'>, choosing TR_S_P3='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P3' types <type 'str'> and <type 'str'>, choosing TR_D_P3='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_S_P3' types <type 'str'> and <type 'str'>, choosing TR_S_P3='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P3' types <type 'str'> and <type 'str'>, choosing TR_D_P3='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P3' types <type 'str'> and <type 'str'>, choosing TR_E_P3='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P3' types <type 'str'> and <type 'str'>, choosing TR_C_P3='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_G_P3' types <type 'str'> and <type 'str'>, choosing TR_G_P3='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P2' types <type 'str'> and <type 'str'>, choosing TR_C_P2='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P3' types <type 'str'> and <type 'str'>, choosing TR_C_P3='fracDev.FracDev' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P4' types <type 'str'> and <type 'str'>, choosing TR_C_P4='shapeExp.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P5' types <type 'str'> and <type 'str'>, choosing TR_C_P5='shapeExp.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P6' types <type 'str'> and <type 'str'>, choosing TR_C_P6='shapeExp.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P7' types <type 'str'> and <type 'str'>, choosing TR_C_P7='shapeDev.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P8' types <type 'str'> and <type 'str'>, choosing TR_C_P8='shapeDev.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P9' types <type 'str'> and <type 'str'>, choosing TR_C_P9='shapeDev.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P2' types <type 'str'> and <type 'str'>, choosing TR_E_P2='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P3' types <type 'str'> and <type 'str'>, choosing TR_E_P3='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P4' types <type 'str'> and <type 'str'>, choosing TR_E_P4='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P5' types <type 'str'> and <type 'str'>, choosing TR_E_P5='shape.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_G_P2' types <type 'str'> and <type 'str'>, choosing TR_G_P2='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_S_P2' types <type 'str'> and <type 'str'>, choosing TR_S_P2='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P2' types <type 'str'> and <type 'str'>, choosing TR_D_P2='brightness.z' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P3' types <type 'str'> and <type 'str'>, choosing TR_D_P3='shape.re' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P4' types <type 'str'> and <type 'str'>, choosing TR_D_P4='shape.e1' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P5' types <type 'str'> and <type 'str'>, choosing TR_D_P5='shape.e2' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P2' types <type 'str'> and <type 'str'>, choosing TR_C_P2='brightness.g' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P2' types <type 'str'> and <type 'str'>, choosing TR_E_P2='brightness.g' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_G_P2' types <type 'str'> and <type 'str'>, choosing TR_G_P2='brightness.g' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_S_P2' types <type 'str'> and <type 'str'>, choosing TR_S_P2='brightness.g' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P2' types <type 'str'> and <type 'str'>, choosing TR_D_P2='brightness.g' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_D_P2' types <type 'str'> and <type 'str'>, choosing TR_D_P2='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_S_P2' types <type 'str'> and <type 'str'>, choosing TR_S_P2='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_E_P2' types <type 'str'> and <type 'str'>, choosing TR_E_P2='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_G_P2' types <type 'str'> and <type 'str'>, choosing TR_G_P2='brightness.r' [astropy.utils.metadata]
WARNING: MergeConflictWarning: Cannot merge meta key 'TR_C_P2' types <type 'str'> and <type 'str'>, choosing TR_C_P2='brightness.r' [astropy.utils.metadata]

Out[11]:
[('Odyssey', 145041),
 ('Alice', 237279),
 ('Gilgamesh', 94874),
 ('AnaK', 182540),
 ('Dune', 231112),
 ('Sopranos', 286959),
 ('Narnia', 158462),
 ('Bandamanna', 59030),
 ('OBrother', 17901),
 ('Catch22', 3951),
 ('HarryPotter', 44918),
 ('Oz', 41667),
 ('ScoobyDoo', 94704),
 ('Othello', 138656)]

In [12]:
for hostobj in tqdm.tqdm_notebook(paperhosts):
    hostobj.cats4 = load_host_catalog(hostobj, 4)
    
[(hostobj.name, len(hostobj.cats4)) for hostobj in paperhosts if hostobj.cats4 is not None]


Widget Javascript not detected.  It may not be installed or enabled properly.

Out[12]:
[('MobyDick', 86799), ('StarTrek', 86644)]

Compute surface brightnesses


In [13]:
for host in tqdm.tqdm_notebook(paperhosts):
    for cat in (host.cats3, host.cats4):
        if cat is not None:
            decals.mags_catalog(cat)
            decals.aperture_sbs_catalog(cat, bandname='r')
            decals.interpolate_catalog_sb(cat, loopfunc=lambda x: tqdm.tqdm_notebook(x, leave=False))


Widget Javascript not detected.  It may not be installed or enabled properly.
decals.py:97: RuntimeWarning: divide by zero encountered in log10
  mag = np.array(22.5 - 2.5*np.log10(flux))
decals.py:97: RuntimeWarning: invalid value encountered in log10
  mag = np.array(22.5 - 2.5*np.log10(flux))
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/astropy/units/quantity.py:885: RuntimeWarning: divide by zero encountered in power
  return super(Quantity, self).__pow__(other)
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/astropy/units/quantity.py:841: RuntimeWarning: divide by zero encountered in true_divide
  return super(Quantity, self).__truediv__(other)
decals.py:132: RuntimeWarning: divide by zero encountered in log10
  return np.array(22.5 - 2.5*np.log10(apflux) + A) * u.mag * u.arcsec**-2
decals.py:132: RuntimeWarning: invalid value encountered in log10
  return np.array(22.5 - 2.5*np.log10(apflux) + A) * u.mag * u.arcsec**-2
Widget Javascript not detected.  It may not be installed or enabled properly.
decals.py:131: RuntimeWarning: divide by zero encountered in log10
  A = 2.5*np.log10(np.pi*(rad.to(u.arcsec).value)**2)
decals.py:132: RuntimeWarning: invalid value encountered in add
  return np.array(22.5 - 2.5*np.log10(apflux) + A) * u.mag * u.arcsec**-2
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.
Widget Javascript not detected.  It may not be installed or enabled properly.

Overall quality measures


In [14]:
psfdepths = []
galdepths = []
for host in paperhosts:
    for cat in (host.cats3, host.cats4):
        if cat is not None:
            scs = SkyCoord(cat['ra'], cat['dec'], unit=u.deg)
            subcat = cat[host.within_environs(scs)]
            
            if 'decam_galdepth' in subcat.colnames:
                psfdepthr = subcat['decam_depth'][:, 2]
                galdepthr = subcat['decam_galdepth'][:, 2]
            else:
                psfdepthr = subcat['psfdepth_r']
                galdepthr = subcat['galdepth_r']
            psfdepths.append(-2.5*(np.log10(5*psfdepthr**-0.5)-9))
            galdepths.append(-2.5*(np.log10(5*galdepthr**-0.5)-9))


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:15: RuntimeWarning: divide by zero encountered in power
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:16: RuntimeWarning: divide by zero encountered in power

In [15]:
psfdepthsall = np.concatenate(psfdepths)
galdepthsall = np.concatenate(galdepths)

plt.hist(psfdepthsall[np.isfinite(psfdepthsall)], bins=100, histtype='step', label='psf')
plt.hist(galdepthsall[np.isfinite(galdepthsall)], bins=100, histtype='step', label='gal')
plt.legend(loc=0)
None


Look at some example catalogs


In [16]:
host = hostobjs[0]
cat = hostobjs[0].cats3

scs = SkyCoord(cat['ra'], cat['dec'], unit=u.deg)
sep = scs.separation(host.coords)
cat = cat[sep < host.environsarcmin*u.arcmin]

In [17]:
fig, ax1 = plt.subplots(1,1)

psfs = cat['type'] == 'PSF '
lowsb_saga = (cat['decam_mag'][:, 2] < 21) & (cat['sbeff_r']>24.5) & np.isfinite(cat['sbeff_r']) & ~psfs
print('nlowsb=', np.sum(lowsb_saga))


ax1.scatter(cat['mag_r'][psfs], cat['sbeff_r'][psfs], alpha=.15, lw=0, c='r')
ax1.scatter(cat['mag_r'][~psfs], cat['sbeff_r'][~psfs], alpha=.25, lw=0)
ax1.scatter(cat['mag_r'][lowsb_saga], cat['sbeff_r'][lowsb_saga], alpha=.35, lw=0, c='g')
ax1.set_ylabel('sberr')    
ax1.set_xlim(15, 26)
ax1.set_ylim(15, 30)

decals.show_decals_objects_in_nb(cat[lowsb_saga], 4, info_cols=['mag_r', 'sbeff_r'])


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:4: RuntimeWarning: invalid value encountered in greater
nlowsb= 44
Out[17]:
2476p202-450
mag_r=20.586271286
sbeff_r=24.5934065751
2476p202-715
mag_r=20.3857479095
sbeff_r=37.2588173046
2477p197-759
mag_r=18.2702465057
sbeff_r=31.1301897295
2478p195-2590
mag_r=20.9697761536
sbeff_r=31.8439584193
2478p195-4282
mag_r=20.7429084778
sbeff_r=26.549063482
2478p200-6
mag_r=20.3502197266
sbeff_r=25.4277524727
2478p200-4396
mag_r=20.6079826355
sbeff_r=24.5260340332
2479p197-29
mag_r=20.3775558472
sbeff_r=25.6079593966
2479p197-563
mag_r=20.5242118835
sbeff_r=25.4743901636
2479p197-714
mag_r=20.6493434906
sbeff_r=25.3186545183
2479p197-2111
mag_r=20.6180858612
sbeff_r=24.5354889939
2479p197-3695
mag_r=20.9754238129
sbeff_r=24.641584166
2479p197-4030
mag_r=20.6593570709
sbeff_r=25.3495706953
2479p197-4369
mag_r=20.1378555298
sbeff_r=24.7682002339
2479p202-354
mag_r=20.5389919281
sbeff_r=24.6013505625
2479p202-640
mag_r=20.5016899109
sbeff_r=25.2728902649
2480p200-14
mag_r=18.9615821838
sbeff_r=36.6034110415
2480p200-895
mag_r=19.555065155
sbeff_r=26.217331135
2480p200-2249
mag_r=19.8074302673
sbeff_r=24.5226214849
2481p195-1000
mag_r=20.1640911102
sbeff_r=30.8877998908
2481p195-2136
mag_r=20.9791736603
sbeff_r=24.6662668753
2481p195-3822
mag_r=19.9327697754
sbeff_r=25.3271228953
2481p195-4807
mag_r=20.192199707
sbeff_r=24.7736447303
2482p197-2
mag_r=20.9094409943
sbeff_r=24.9487199525
2482p197-2225
mag_r=20.7546653748
sbeff_r=25.3396845211
2482p197-2782
mag_r=20.4544353485
sbeff_r=25.0661888613
2483p200-4646
mag_r=20.674659729
sbeff_r=24.9101549915
2483p200-4820
mag_r=16.8170909882
sbeff_r=27.0380857554
2484p195-1594
mag_r=20.4528598785
sbeff_r=24.8357065085
2484p195-2152
mag_r=20.6783103943
sbeff_r=24.8681923513
2484p195-3850
mag_r=19.0855007172
sbeff_r=25.9648771675
2484p195-4008
mag_r=20.9257411957
sbeff_r=24.9253028899
2484p195-4106
mag_r=20.5365161896
sbeff_r=24.9131450537
2484p195-4211
mag_r=20.3484573364
sbeff_r=24.7892367038
2484p202-12
mag_r=20.6151332855
sbeff_r=25.3657091122
2484p202-706
mag_r=17.0301151276
sbeff_r=46.010157039
2485p197-63
mag_r=20.5360221863
sbeff_r=24.9274481718
2485p197-920
mag_r=20.6391067505
sbeff_r=24.9585070986
2485p197-2011
mag_r=20.7921562195
sbeff_r=24.5510897803
2485p197-2341
mag_r=20.6563034058
sbeff_r=24.778729949
2485p197-3931
mag_r=20.7784938812
sbeff_r=25.3640245688
2486p200-661
mag_r=20.0164432526
sbeff_r=35.1741778164
2486p200-4152
mag_r=20.6913909912
sbeff_r=24.7619793186
2486p200-4292
mag_r=16.7704925537
sbeff_r=27.2917213985

In [18]:
fig, ax1 = plt.subplots(1,1)

cat['decam_mag_r'] = cat['decam_mag'][:, 2]

psfs = cat['type'] == 'PSF '

lowsb_saga = (cat['decam_mag'][:, 2] < 21) & (cat['sb_r_0p5']>24.5) & np.isfinite(cat['sb_r_0p5']) & ~psfs
print('nlowsb=', np.sum(lowsb_saga))

ax1.scatter(cat['mag_r'][psfs], cat['sb_r_0p5'][psfs], alpha=.15, lw=0, c='r')
ax1.scatter(cat['mag_r'][~psfs], cat['sb_r_0p5'][~psfs], alpha=.25, lw=0)
ax1.scatter(cat['mag_r'][lowsb_saga], cat['sb_r_0p5'][lowsb_saga], alpha=.35, lw=0, c='g')
ax1.set_ylabel('sberr')    
ax1.set_xlim(15, 26)
ax1.set_ylim(15, 30)

decals.show_decals_objects_in_nb(cat[lowsb_saga], 4, info_cols=['decam_mag_r', 'sb_r_0p5'])


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:7: RuntimeWarning: invalid value encountered in greater
nlowsb= 100
Out[18]:
2475p200-1824
decam_mag_r=20.8320064545
sb_r_0p5=25.8713417053
2476p195-3690
decam_mag_r=20.7130851746
sb_r_0p5=24.5412139893
2476p195-4168
decam_mag_r=20.0663070679
sb_r_0p5=25.8236122131
2476p195-4827
decam_mag_r=20.9686107635
sb_r_0p5=26.0192279816
2476p202-15
decam_mag_r=20.2626590729
sb_r_0p5=25.7077674866
2476p202-17
decam_mag_r=20.2105484009
sb_r_0p5=25.468755722
2476p202-450
decam_mag_r=20.586271286
sb_r_0p5=24.5258750916
2477p197-413
decam_mag_r=19.8963317871
sb_r_0p5=25.1386890411
2477p197-3923
decam_mag_r=20.9988746643
sb_r_0p5=27.1462554932
2478p195-95
decam_mag_r=19.7930049896
sb_r_0p5=24.5665283203
2478p195-325
decam_mag_r=20.1033248901
sb_r_0p5=25.2297267914
2478p195-1028
decam_mag_r=18.9320335388
sb_r_0p5=27.8153553009
2478p195-1874
decam_mag_r=20.0043945312
sb_r_0p5=25.4510002136
2478p195-2961
decam_mag_r=20.8558578491
sb_r_0p5=25.6708717346
2478p200-6
decam_mag_r=20.3502197266
sb_r_0p5=25.0052585602
2478p200-786
decam_mag_r=20.2602539062
sb_r_0p5=25.3732528687
2478p200-1187
decam_mag_r=20.1321792603
sb_r_0p5=26.683555603
2478p200-1887
decam_mag_r=20.5993843079
sb_r_0p5=25.4464988708
2479p197-29
decam_mag_r=20.3775558472
sb_r_0p5=24.5118160248
2479p197-481
decam_mag_r=17.9029045105
sb_r_0p5=24.5105476379
2479p197-714
decam_mag_r=20.6493434906
sb_r_0p5=24.7115020752
2479p197-1084
decam_mag_r=19.7665653229
sb_r_0p5=24.7168273926
2479p197-1090
decam_mag_r=20.7665500641
sb_r_0p5=25.408367157
2479p197-2102
decam_mag_r=20.6970787048
sb_r_0p5=25.489440918
2479p197-3528
decam_mag_r=18.9746818542
sb_r_0p5=25.2143478394
2479p197-3530
decam_mag_r=20.9648303986
sb_r_0p5=25.5067310333
2479p197-3533
decam_mag_r=20.0532817841
sb_r_0p5=24.8457717896
2479p197-3917
decam_mag_r=20.1422767639
sb_r_0p5=24.7016124725
2479p197-4030
decam_mag_r=20.6593570709
sb_r_0p5=25.4709396362
2479p202-17
decam_mag_r=19.2327575684
sb_r_0p5=26.6582336426
2479p202-146
decam_mag_r=20.000415802
sb_r_0p5=24.7684459686
2479p202-413
decam_mag_r=20.5035037994
sb_r_0p5=25.3698940277
2479p202-640
decam_mag_r=20.5016899109
sb_r_0p5=25.2504234314
2479p202-783
decam_mag_r=20.736415863
sb_r_0p5=28.8750305176
2479p202-922
decam_mag_r=20.725227356
sb_r_0p5=26.1174087524
2479p202-924
decam_mag_r=19.4923820496
sb_r_0p5=24.6771850586
2479p202-925
decam_mag_r=19.7908363342
sb_r_0p5=25.0970573425
2479p202-1330
decam_mag_r=20.7755432129
sb_r_0p5=24.8736400604
2479p202-1959
decam_mag_r=20.8785552979
sb_r_0p5=24.5021629333
2479p202-2122
decam_mag_r=19.7316741943
sb_r_0p5=27.0637187958
2479p202-3156
decam_mag_r=20.4263362885
sb_r_0p5=24.6956920624
2480p192-4018
decam_mag_r=20.116481781
sb_r_0p5=24.5581169128
2480p192-4019
decam_mag_r=20.3163013458
sb_r_0p5=24.6080570221
2480p200-165
decam_mag_r=20.0567836761
sb_r_0p5=25.2187690735
2480p200-1904
decam_mag_r=20.3388996124
sb_r_0p5=25.224729538
2480p200-2274
decam_mag_r=20.3150558472
sb_r_0p5=26.1484298706
2480p200-3787
decam_mag_r=20.9786663055
sb_r_0p5=24.6672210693
2480p200-3799
decam_mag_r=20.6640071869
sb_r_0p5=25.8559761047
2480p200-4134
decam_mag_r=20.8517589569
sb_r_0p5=25.5473480225
2480p200-4532
decam_mag_r=20.8073120117
sb_r_0p5=26.3350963593
2480p200-4660
decam_mag_r=20.0851612091
sb_r_0p5=25.4503688812
2481p195-747
decam_mag_r=19.2568187714
sb_r_0p5=25.6650676727
2481p195-804
decam_mag_r=19.9055404663
sb_r_0p5=27.0201320648
2481p195-1004
decam_mag_r=20.8188381195
sb_r_0p5=26.7559871674
2481p195-1113
decam_mag_r=20.460899353
sb_r_0p5=25.1161308289
2481p195-1844
decam_mag_r=19.8077220917
sb_r_0p5=25.4247608185
2481p195-1846
decam_mag_r=20.3571357727
sb_r_0p5=28.5607147217
2481p195-1911
decam_mag_r=20.8080596924
sb_r_0p5=24.5485229492
2481p195-1934
decam_mag_r=19.8383789062
sb_r_0p5=25.7853851318
2481p195-3822
decam_mag_r=19.9327697754
sb_r_0p5=24.5445194244
2481p202-995
decam_mag_r=20.308681488
sb_r_0p5=24.7583198547
2482p197-541
decam_mag_r=18.7847290039
sb_r_0p5=24.53840065
2482p197-983
decam_mag_r=20.6635856628
sb_r_0p5=25.2793998718
2482p197-1114
decam_mag_r=20.0146274567
sb_r_0p5=25.3894062042
2482p197-1548
decam_mag_r=19.6889152527
sb_r_0p5=24.6511993408
2482p197-2405
decam_mag_r=20.8500022888
sb_r_0p5=24.743844986
2482p197-2989
decam_mag_r=19.6963768005
sb_r_0p5=24.8897266388
2482p197-3637
decam_mag_r=20.4267845154
sb_r_0p5=26.0662059784
2482p197-3826
decam_mag_r=19.7426261902
sb_r_0p5=24.6148738861
2482p197-4461
decam_mag_r=20.5642585754
sb_r_0p5=25.2006130219
2482p197-4954
decam_mag_r=19.0049514771
sb_r_0p5=24.5194091797
2483p200-351
decam_mag_r=20.8899974823
sb_r_0p5=24.5168514252
2483p200-417
decam_mag_r=19.3195972443
sb_r_0p5=24.8662052155
2483p200-442
decam_mag_r=20.7671337128
sb_r_0p5=25.5518798828
2483p200-624
decam_mag_r=20.2175655365
sb_r_0p5=24.869846344
2483p200-4798
decam_mag_r=20.8821525574
sb_r_0p5=24.798576355
2484p195-1678
decam_mag_r=20.439863205
sb_r_0p5=25.5077171326
2484p195-2152
decam_mag_r=20.6783103943
sb_r_0p5=24.8138370514
2484p195-2239
decam_mag_r=19.9200744629
sb_r_0p5=27.8892803192
2484p195-2296
decam_mag_r=20.3159008026
sb_r_0p5=25.2589740753
2484p195-2514
decam_mag_r=20.9379844666
sb_r_0p5=24.546453476
2484p195-3071
decam_mag_r=20.488363266
sb_r_0p5=26.7100791931
2484p195-3676
decam_mag_r=20.5650100708
sb_r_0p5=25.1569328308
2484p195-4221
decam_mag_r=20.7257957458
sb_r_0p5=26.6991062164
2484p202-328
decam_mag_r=20.2660236359
sb_r_0p5=24.8052024841
2484p202-1012
decam_mag_r=20.240032196
sb_r_0p5=24.6243686676
2485p197-87
decam_mag_r=20.9683532715
sb_r_0p5=25.4621047974
2485p197-133
decam_mag_r=19.2758350372
sb_r_0p5=24.555147171
2485p197-135
decam_mag_r=19.6749382019
sb_r_0p5=24.5699768066
2485p197-291
decam_mag_r=20.4851646423
sb_r_0p5=26.732170105
2485p197-404
decam_mag_r=18.871049881
sb_r_0p5=25.6585578918
2485p197-1670
decam_mag_r=19.9854011536
sb_r_0p5=25.4507160187
2485p197-2341
decam_mag_r=20.6563034058
sb_r_0p5=24.6169548035
2485p197-2926
decam_mag_r=20.4512615204
sb_r_0p5=25.6820449829
2485p197-3931
decam_mag_r=20.7784938812
sb_r_0p5=24.5917930603
2485p197-4120
decam_mag_r=20.3987998962
sb_r_0p5=25.520565033
2486p200-436
decam_mag_r=20.628572464
sb_r_0p5=24.5998840332
2486p200-662
decam_mag_r=19.3991794586
sb_r_0p5=25.0488204956
2486p200-1025
decam_mag_r=20.6248455048
sb_r_0p5=24.5220470428
2486p200-1130
decam_mag_r=19.8986301422
sb_r_0p5=24.9427032471

This strongly suggests that sbeff_r is the way to go

Check for SDSS overlap


In [19]:
for host in tqdm.tqdm_notebook(paperhosts):
    try:
        sdsscat = host.get_sdss_catalog()
    except IOError:
        print('Missing base catalog for', host.name)
        sdsscat = None
    
    for cat in (host.cats3, host.cats4):
        
        if cat is not None:
            d2ds = np.full(len(cat), -1, dtype=float)
            if sdsscat is not None:
                dcatsc = SkyCoord(cat['ra'], cat['dec'], unit=u.deg)
                idx, d2d, _ = dcatsc.match_to_catalog_sky(sdsscat['coord'])

                plt.figure()
                plt.hist(d2d.arcsec, bins=1000, histtype='step',range=(0, 30), log=True)
                plt.axvline(1, c='k', ls='--')
                plt.axvline(3, c='k')
                plt.title(host.name)
                d2ds = d2d.to(u.arcsec)
                
            cat['dist_basecat'] = d2ds
            cat['dist_basecat'].description = '-1 means "unknown", e.g. base catalog missing'


Widget Javascript not detected.  It may not be installed or enabled properly.
Could not find file "catalogs/base_sql_nsa13927.fits.gz" but did find "catalogs/NSA13927_sdss.dat" so using that.
Could not find file "catalogs/base_sql_nsa85746.fits.gz" but did find "catalogs/NSA85746_sdss.dat" so using that.
Could not find file "catalogs/base_sql_nsa33446.fits.gz" but did find "catalogs/NSA33446_sdss.dat" so using that.
Missing base catalog for Oz
Missing base catalog for ScoobyDoo
Could not find file "catalogs/base_sql_nsa145729.fits.gz" but did find "catalogs/NSA145729_sdss.dat" so using that.

Build the combined list of candidate objects


In [ ]:


In [51]:
maxnamelen = max([len(h.name) for h in paperhosts])

tostack = []
for host in tqdm.tqdm_notebook(paperhosts):
    for drnum, cat in [(3, host.cats3), (4, host.cats4)]:
        if cat is not None:
            psfs = cat['type'] == 'PSF '
            lowsb_saga = (cat['mag_r'] < 21) & (cat['sbeff_r']>24.5) & np.isfinite(cat['sbeff_r']) & ~psfs
            subcat = cat[lowsb_saga]['objname', 'ra', 'dec', 'mag_r', 'sbeff_r', 'dist_basecat']
            subcat['dr'] = np.full(len(subcat), drnum, dtype=int)
            subcat['hostname'] = np.full(len(subcat), host.name, dtype='S'+str(maxnamelen))
            tostack.append(subcat)
            
towrite = table.vstack(tostack)
towrite.sort(['hostname', 'dist_basecat'])
towrite.meta = {}

towrite['inbasecat'] = np.full(len(towrite), 'unknown', dtype='S'+str(len('unknown')))
towrite['inbasecat'][towrite['dist_basecat'] > 0*u.arcsec] = 'yes'
towrite['inbasecat'][towrite['dist_basecat'] > 1*u.arcsec] = 'maybe'
towrite['inbasecat'][towrite['dist_basecat'] > 3*u.arcsec] = 'no'
towrite['inbasecat'].description = 'estimate of "is this in the base catalogs": <1 arcsec is yes, 1-3 is maybe, >3 is no'

towrite


/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:8: RuntimeWarning: invalid value encountered in less
/Users/erik/miniconda3/envs/saga/lib/python2.7/site-packages/ipykernel/__main__.py:8: RuntimeWarning: invalid value encountered in greater

Out[51]:
<Table length=2326>
objnameradecmag_rsbeff_rdist_basecatdrhostnameinbasecat
degdegmagmag / arcsec2arcsec
str13float64float64float32float64float64int64str11str7
1793m010-3424179.392364348-0.94921885280720.640424.68343021370.02781083436483Aliceyes
1793m005-2489179.405986637-0.5020040354819.840425.04345448130.07226996659253Aliceyes
1801m002-578180.009418942-0.34866545386118.336240.52339661130.08147161124113Aliceyes
1808m007-4276180.785549654-0.62266165433820.881534.98249371160.08200402133093Aliceyes
1803m002-3301180.357553868-0.17115294851419.485841.31066517710.08477864835673Aliceyes
1796m005-1750179.541905943-0.54004923644416.454837.45999881030.09410921920553Aliceyes
1803m002-3331180.38212919-0.172041720319.41633.79184014110.0998825240053Aliceyes
1796m002-783179.609997374-0.33624182979316.577839.03739204880.1008052602633Aliceyes
1801m002-2245180.109975356-0.26132552082120.213825.26142197990.1048357639273Aliceyes
...........................
1226p362-1710122.58570164336.264094552520.957825.508345012527.86448534094StarTrekno
1224p365-1440122.34078104536.495503897720.971424.609100073927.92784031694StarTrekno
1232p362-3060123.20972088536.322071172120.955225.688290248728.5645820564StarTrekno
1232p362-3057123.20972088536.322071172120.955225.688290248728.56458206054StarTrekno
1228p360-567122.73240250135.914004564320.119327.442074780228.9795075294StarTrekno
1228p360-689122.72478783335.92289677320.620925.277571287730.77607042114StarTrekno
1236p365-2305123.7924764136.537931706120.614324.919008660530.7952223724StarTrekno
1236p357-1908123.47422013835.763981113420.489525.054846994132.0443307484StarTrekno
1230p365-1904123.19822656636.511709321920.644926.564420684434.82449681554StarTrekno
1230p365-257123.11956366736.390317381520.983125.04687588835.07856145624StarTrekno

In [58]:
htmlyes = decals.show_decals_objects_in_nb(towrite[towrite['inbasecat']=='yes'], dr='fromcatalog', nrows=4,
                                           info_cols=['mag_r', 'sbeff_r', 'hostname', 'dr', 'dist_basecat'], sdss_link=True)
htmlnotyes = decals.show_decals_objects_in_nb(towrite[towrite['inbasecat']!='yes'], dr='fromcatalog', nrows=4,
                                           info_cols=['mag_r', 'sbeff_r', 'hostname', 'dr', 'dist_basecat'], sdss_link=True)

with open('lowsb_decals_notinbasecat.html', 'w') as f:
    f.write('<!doctype html>\n<meta charset=utf-8>\n<title>LowSB SAGA Decals object not in basecat</title>\n')
    f.write('<h1>Non-basecat overlaps</h1>\n')
    f.write(htmlnotyes.data)
    
with open('lowsb_decals_inbasecat.html', 'w') as f:   
    f.write('<!doctype html>\n<meta charset=utf-8>\n<title>LowSB SAGA Decals objects in basecat</title>\n')
    f.write('<h1>Already in basecats</h1>\n')
    f.write(htmlyes.data)

In [59]:
towrite.write('/Users/erik/Dropbox/SAGA/temporary/lowsbs_decals.dat', format='ascii.ecsv')
!cp lowsb_decals*.html /Users/erik/Dropbox/SAGA/temporary/